﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// 数据访问类:ItemPurchaseEntry
    /// </summary>
    public partial class ItemPurchaseEntry
    {
        public ItemPurchaseEntry()
        { }
        #region  BasicMethod
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_Admin_DSJCJ.Model.ItemPurchaseEntry GetModel(decimal FItemPurchaseEntryID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FItemPurchaseEntryID,FEntityNo,FItemNo,FQty,FPrice,FAmount,FItemPurchaseID,FPurchaseDate from dbo.t_ItemPurchaseEntry ");
            strSql.Append(" where FItemPurchaseEntryID=@FItemPurchaseEntryID");
            SqlParameter[] parameters = {
					new SqlParameter("@FItemPurchaseEntryID", SqlDbType.Decimal)
			};
            parameters[0].Value = FItemPurchaseEntryID;

            ElingOA6_Admin_DSJCJ.Model.ItemPurchaseEntry model = new ElingOA6_Admin_DSJCJ.Model.ItemPurchaseEntry();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_Admin_DSJCJ.Model.ItemPurchaseEntry DataRowToModel(DataRow row)
        {
            ElingOA6_Admin_DSJCJ.Model.ItemPurchaseEntry model = new ElingOA6_Admin_DSJCJ.Model.ItemPurchaseEntry();
            if (row != null)
            {
                if (row["FItemPurchaseEntryID"] != null && row["FItemPurchaseEntryID"].ToString() != "")
                {
                    model.FItemPurchaseEntryID = decimal.Parse(row["FItemPurchaseEntryID"].ToString());
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FItemNo"] != null)
                {
                    model.FItemNo = row["FItemNo"].ToString();
                }
                if (row["FQty"] != null && row["FQty"].ToString() != "")
                {
                    model.FQty = decimal.Parse(row["FQty"].ToString());
                }
                if (row["FPrice"] != null && row["FPrice"].ToString() != "")
                {
                    model.FPrice = decimal.Parse(row["FPrice"].ToString());
                }
                if (row["FAmount"] != null && row["FAmount"].ToString() != "")
                {
                    model.FAmount = decimal.Parse(row["FAmount"].ToString());
                }
                if (row["FItemPurchaseID"] != null && row["FItemPurchaseID"].ToString() != "")
                {
                    model.FItemPurchaseID = decimal.Parse(row["FItemPurchaseID"].ToString());
                }
                if (row["FPurchaseDate"] != null && row["FPurchaseDate"].ToString() != "")
                {
                    model.FPurchaseDate = DateTime.Parse(row["FPurchaseDate"].ToString());
                }
                if (row.Table.Columns.Contains("FItemName"))
                {
                    if (row["FItemName"] != null && row["FItemName"].ToString() != "")
                    {
                        model.FItemName = row["FItemName"].ToString();
                    }
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  a.FItemPurchaseEntryID,a.FEntityNo,a.FItemNo,a.FQty,a.FPrice,a.FAmount,FItemPurchaseID,FPurchaseDate ,b.FItemName ");
            strSql.Append(" FROM dbo.t_ItemPurchaseEntry a  LEFT JOIN dbo.t_Item b ON a.FItemNo = b.FItemNo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }


        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "t_ItemPurchaseEntry";
            parameters[1].Value = "FItemPurchaseEntryID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

